home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SD2.ASM < prev    next >
Assembly Source File  |  1987-05-15  |  15KB  |  412 lines

  1. ;------------------------------------------------------------------------------;
  2. ;                                                                              ;
  3. ;                                                                              ;
  4. ;                                                                              ;
  5. ; Switch Directory - SD                                                        ;
  6. ;                                                                              ;
  7. ;                                                                              ;
  8. ;                                                                              ;
  9. ;Usage                                                                         ;
  10. ;                                                                              ;
  11. ;   [d:\....]>SD [drive][switch][subdirectory name]                            ;
  12. ;                                                                              ;
  13. ;                        [drive] - the drive to search (if not searhing        ;
  14. ;                                  current drive)                              ;
  15. ;                                                                              ;
  16. ;                        [switch] = blank - search whole disk                  ;
  17. ;                                                                              ;
  18. ;                                 = \ - search only subdirectories of the      ;
  19. ;                                       current directory                      ;
  20. ;                                                                              ;
  21. ;                                 = / - search only one path deep. Searches    ;
  22. ;                                       the root directory only. (Similar      ;
  23. ;                                       to DOS CD command with one pathname)   ;
  24. ;                                                                              ;
  25. ;                                                                              ;
  26. ;                                                                              ;
  27. ;                        [subdirectory name] - the name of an individual       ;
  28. ;                                              subdirectory (not the           ;
  29. ;                                              complete path)                  ;
  30. ;                                                                              ;
  31. ;                        If the command line is left blank then you are        ;
  32. ;                        taken to the root directory of the disk               ;
  33. ;                                                                              ;
  34. ;                                                                              ;
  35. ;Sorce code heavily dependent on Vern Buerg's LDIR program. Thanks Vern        ;
  36. ;                                                                              ;
  37. ;3/11/87 - Stephen Falatko                                                     ;
  38. ;                                                                              ;
  39. ;Written for the A86 assembler                                                 ;
  40. ;                                                                              ;
  41. ;------------------------------------------------------------------------------;
  42.       ;    Simple change directory
  43.  
  44. CODE SEGMENT
  45.  
  46.       Org    0100
  47.  
  48. Stackx       Dw      0                       ;Entry stack pointer
  49.  
  50.       Mov    Stackx,SP               ;Save stack ptr for exiting
  51.       Jmp    Start
  52. ;
  53. ;     Data Areas, Constants, Etc.
  54.  
  55. LF           Equ     10
  56. CR           Equ     13
  57. Stopper      Equ     255                    ;Ends print strings
  58.  
  59. CURDSK       Equ     019                     ;Get current disk
  60. SETDTA       Equ     01A                     ;Set data transfer area
  61. CHDIR        Equ     03B                     ;Change directory
  62. GETPATH      Equ     047                     ;Get current directory
  63.  
  64. Errlvl       Db      0                       ;DOS return code
  65.  
  66. RootFlag     Db      0
  67. OneDeepFlag  Db      0
  68.  
  69. Sub_Dir      Db      16 Dup (0)              ;The sub dir we want to change to
  70.  
  71. Done_Flag    Dw      0
  72.  
  73. Count        Dw      0                       ;Number of args on command line
  74.  
  75. DtaPointer   Dw      DtaAreaBegin
  76. Direction    Db      0
  77. BackOneDir   Db      '..',0
  78. SearchAsciiZ Db      '*.*',0
  79.  
  80. ;
  81. ;     Headings and titles
  82.  
  83. Not_Found_Msg  Db  CR,LF,'Subdirectory Not Found',CR,LF,Stopper
  84. PathErrorMsg   Db  CR,LF,'Illegal \ charater in path name',CR,LF,Stopper
  85.  
  86. Help           Db  CR,LF,'Usage:',CR,LF,CR,LF
  87.                Db  '[d:\....]>SD [drive][switch][subdirectory name]',CR,LF
  88.                Db  '      [drive] - the drive to search. (if not searching',CR,LF
  89.                Db  '                current drive)',CR,LF,CR,LF
  90.                Db  '      [switch] = blank - search whole disk',CR,LF,CR,LF
  91.                Db  '               = \ - search only subdirectories of the',CR,LF
  92.                Db  '                     current directory',CR,LF,CR,LF
  93.                Db  '               = / - search only one path deep. Searches',CR,LF
  94.                Db  '                     the root directory only. (Similar',CR,LF
  95.                Db  '                     to DOS CD command with one pathname)',CR,LF,CR,LF
  96.                Db  '      [subdirectory name] - the name of an individual',CR,LF
  97.                Db  '                            subdirectory (not the',CR,LF
  98.                Db  '                            complete path)',CR,LF
  99.                Db  '      If the command line is left blank then you are',CR,LF
  100.                Db  '      taken to the root directory of the disk',CR,LF,Stopper
  101.  
  102. OrigDr       Db      'x:'                    ;Original drive
  103. OrigDir      Db      '\',63 Dup (0)          ; and path
  104.  
  105. RootDir      Db      'x:\',0                 ;To get vol label
  106.  
  107.  
  108. ;
  109. ;     Set default drive and path
  110.  
  111. Start:
  112.       Mov    AH,0D                   ; Reset diskettes
  113.       Int    021
  114.  
  115.       Mov    AH,CURDSK               ; Get current disk
  116.       Int    021
  117.       Add    AL,'A'
  118.       Mov    OrigDr,AL               ; Save original drive letter
  119.       Mov    RootDir,AL              ;
  120.  
  121.       Mov    AH,GETPATH              ; Save original path
  122.       Mov    DL,OrigDr
  123.       Sub    DL,'@'                  ; a little monkey business to set
  124.       Mov    SI,Offset OrigDir + 1   ; the original drive
  125.       Int    021
  126.  
  127.       Mov    AX,02523                ; set Ctrl+Break vector to point
  128.       Mov    DX,Offset NFCB          ; to our not found. This way a Ctrl+Brk
  129.       Int    021                     ; will leave us in the place we started
  130.  
  131.       Sub    CX,CX                   ; Clear CX
  132.       Mov    CL,B [080]              ; Get the number of characters in
  133.  
  134.       Cmp    CX,0                    ; Anything?
  135.       Jne    L1
  136.       Call No_Arg                    ;set root dir and leave
  137.       Jmp    Exit
  138.   L1:
  139.       Mov    SI,081                  ; set up to parse command line
  140.       Mov    DI,Offset Sub_dir
  141.  
  142.       Push   DI
  143.       Mov    DI,SI
  144.       Mov    al,':'                  ;drive specifier present?
  145.       Repne  Scasb
  146.       Cmp    B [DI-1],':'
  147.       Jne    L10
  148.       Mov    SI,DI                   ;point SI to character following :
  149.       Sub    DI,2                    ;point DI to drive letter
  150.       Mov    AL,B [DI]
  151.       Xor    AL,020
  152.       Mov    RootDir,AL
  153.  
  154.       Sub    DX,DX
  155.       Mov    AH,0E                   ; set drive
  156.       Mov    DL,AL
  157.       Sub    DL,'A'
  158.       Int    021
  159.  
  160.       Cmp    B [SI],CR
  161.       If e Call No_Arg
  162.  
  163.       Pop    DI
  164.       Jmp Short L2
  165.   L10:
  166.       Pop    DI
  167.   L2:
  168.       Lodsb
  169.  
  170.       Cmp    AL,' '                  ;strip leading blanks
  171.       Jz     L2
  172.  
  173.       Cmp    AL,0D                   ;carriage return
  174.       Jz     L7
  175.  
  176.       Cmp    AL,'?'                  ;?
  177.       Jne    L3
  178.       Cmp    DI,Offset Sub_Dir       ;still pointing to beginning?
  179.       Jne    L3
  180.       Mov    DX,Offset Help
  181.       Call PrintS
  182.       Jmp    Exit                    ;load next
  183.   L3:
  184.       Cmp    AL,'